/**
 * Created by CK on 2016/6/22.
 */
$(document).ready(function(){
    var schoolId = xhTool.getQuery('iSchoolId');
    var list = $('#List');
    $('.xh-datagrid-toolbar').parseToolbar();
    list.initDataGrid(baseUrl + 'School/getAppDgData', {"queryParams": {"iSchoolId": schoolId, "type": "in"}})
        .setSelectThenEnable(['bt_list_del', 'bt_list_Update', 'bt_list_enable', 'bt_list_disable', 'bt_list_DownEnable', 'bt_list_DownDisable']);
    /** 列表 **/
    $('#bt_list_del').click(function(){
        var ids = list.getDataGridSelectedFields('iSASId');
        $.overtFun.clickDelList(ids, 'delSchoolApp?iSchoolId=' + schoolId);
    });
    $('#bt_list_add').click(function () {
        var src = baseUrl + 'School/schoolOutAppList?iSchoolId=' + schoolId;
        window.top.xhTop.showModal({
            title: '学校关联应用',
            content: "<iframe frameborder='0' style='width: 100%;height: 500px;' src='" + src + "'></iframe>",
            button: '确认关联',
            size: 'lg'
        });
    });
    //更新按钮
    $('#bt_list_Update').click(function(){
        if($(this).checkButtonDisabled()) return false;
        var schoolAppIds = list.getDataGridSelectedFields('iSASId');
        if(!schoolAppIds) return false;
        $.post('updateSchoolApp', {sSASId: schoolAppIds, iSchoolId: schoolId}, function (result) {
            if (result == 1) {
                list.dataGridReload();
                $('#bt_list_Update').setButtonDisable('eu');
            }
            else $('body').append(result);
        });
    });
    //全部更新按钮
    $('#bt_list_UpdateAll').click(function(){
        $.post('updateSchoolApp',{iSchoolId: schoolId, sSASId: 'all'}, function(result){
            if(result == 1) list.dataGridReload();//刷新
            else $('body').append(result);
        });
    });
    //启用按钮
    $('#bt_list_enable').click(function(){
        if($(this).checkButtonDisabled()) return false;
        var schoolAppIds = list.getDataGridSelectedFields('iSASId');
        $.overtFun.setModelState('setSchoolAppState?iSchoolId=' + schoolId , schoolAppIds, 'enable');
        //setSchoolAppState('enable');
    });
    //禁用按钮
    $('#bt_list_disable').click(function(){
        if($(this).checkButtonDisabled()) return false;
        var schoolAppIds = list.getDataGridSelectedFields('iSASId');
        $.overtFun.setModelState('setSchoolAppState?iSchoolId=' + schoolId , schoolAppIds, 'disable');
        //setSchoolAppState('disable');
    });
    //启用下载按钮
    $('#bt_list_DownEnable').click(function(){
        if($(this).checkButtonDisabled()) return false;
        var schoolAppIds = list.getDataGridSelectedFields('iSASId');
        $.overtFun.setModelState('setSchoolAppState?iSchoolId=' + schoolId , schoolAppIds, 'downEnable');
        //setSchoolAppState('downEnable');
    });
    //禁用下载按钮
    $('#bt_list_DownDisable').click(function(){
        if($(this).checkButtonDisabled()) return false;
        var schoolAppIds = list.getDataGridSelectedFields('iSASId');
        $.overtFun.setModelState('setSchoolAppState?iSchoolId=' + schoolId , schoolAppIds, 'downDisable');
        //setSchoolAppState('downDisable');
    });
});
//function del() {
//    var ids = list.getDataGridSelectedFields('iSASId');
//    $.post('delSchoolApp',{ids:ids},function(result){
//        alertMessage('结果',result);//弹窗提示
//        list.dataGridReload();//刷新
//    });
//}
//function setSchoolAppState(target){
//    var schoolAppIds = list.getDataGridSelectedFields('iSASId');
//    $.post('setSchoolAppState',{sSASId:schoolAppIds,target:target},function(result){
//        if(result == 1) list.dataGridReload();//刷新
//        else $('body').append(result);
//    });
//}